﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlServerCe;

namespace CPTECH.Repository
{
    class usersDB: BaseDB
    {
        private static usersDB instance;

        private usersDB() { }

        public static usersDB getInstance()
        {
            if (instance == null)
            {
                instance = new usersDB();
            }
            return instance;
        }

        //verifica se usuário existe ou não.
        public bool checkUser(string user, string senha)
        {
            try
            {
                this.open();
                SqlCeCommand command = new SqlCeCommand("SELECT * FROM TB_USERS WHERE LOGIN=@user and PASSWD=@senha;", this.conn);
                command.Parameters.AddWithValue("@user", user);
                command.Parameters.AddWithValue("@senha", senha);
                SqlCeDataReader rdr = command.ExecuteReader();
                bool result = false;
                
                while (rdr.Read())
                {
                    result = true;
                }

                return result;
            }
            finally
            {
                this.close();
            }
        }
    }
}
